package com.example.jdt_xiazai.net;


import java.io.File;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpUtil {
    private Retrofit.Builder builder;
    private static volatile  HttpUtil httpUtil=null;
    private HttpUtil() {
        getRetrofit();
    }

    private void getRetrofit() {
         builder = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
    }



    public  static HttpUtil getHttpUtil(){
        if (httpUtil==null){
            synchronized (HttpUtil.class){
                if (httpUtil==null){
                    httpUtil=new HttpUtil();
                }
            }
        }
        return httpUtil;
    }


    volatile ApiService apiService;
    public ApiService getApiService(){
        if (apiService==null){
            synchronized (HttpUtil.class){
                if (apiService==null){
                    apiService=builder.baseUrl(ApiService.str)
                            .build()
                            .create(ApiService.class);

                }
            }
        }
        return apiService;
    }
}
